using System.Collections.Generic;
using System.Xml;

namespace Framework.Library.Core.Utils.GlobalHelper
{
    public class TemplateHelper
    {
        private readonly string xmlPath = string.Empty;

        public TemplateHelper()
        {
        }

        public  TemplateHelper(string strXmlPath)
        {
            xmlPath = strXmlPath;
        }

        private XmlDocument doc
        {
            get { return LoadXMLDocument(xmlPath); }
        }

        private XmlDocument LoadXMLDocument(string xmlPath)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.Load(xmlPath);
            return xmlDocument;
        }

        public Dictionary<string, string> GetMetas()
        {
            XmlNodeList nodeList = doc.SelectNodes("//metas//meta");
            var lst = new Dictionary<string, string>();
            for (int i = 0; i < nodeList.Count; i++)
            {
                lst.Add(nodeList.Item(i).Attributes["name"].InnerXml, nodeList.Item(i).InnerText);
            }
            return lst;
        }

        public string[] GetCss()
        {
            XmlNodeList nodeList = doc.SelectNodes("//resources//css//filename");
            var lst = new string[nodeList.Count];
            for (int i = 0; i < nodeList.Count; i++)
            {
                lst[i] = nodeList.Item(i).InnerText;
            }
            return lst;
        }

        public string[] GetJavascript()
        {
            XmlNodeList nodeList = doc.SelectNodes("//resources//javascript//filename");
            var lst = new string[nodeList.Count];
            for (int i = 0; i < nodeList.Count; i++)
            {
                lst[i] = nodeList.Item(i).InnerText;
            }
            return lst;
        }

        public string[] GetPlaceholder()
        {
            XmlNodeList nodeList = doc.SelectNodes("//placeholders//placeholder");
            var lst = new string[nodeList.Count];
            for (int i = 0; i < nodeList.Count; i++)
            {
                lst[i] = nodeList.Item(i).InnerText;
            }
            return lst;
        }
    }
}